<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        .gridtable {
            font-family: verdana,arial,sans-serif;
            font-size:11px;
            color:#333333;
            border-width: 1px;
            border-color: #666666;
            border-collapse: collapse;
        }
        .gridtable th {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #dedede;
        }
        .gridtable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <table width="500px" align="center" class="gridtable">
        <th>电影id</th>
        <th>电影名称</th>
        <th>电影评分</th>
    </table>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
    $(document).ready(function() {
        $.get("http://localhost:8081/getlist", function(data) {
            console.log("获取到的电影数据:", data);
            
            try {
                const movies = typeof data === 'string' ? JSON.parse(data) : data;
                
                if (Array.isArray(movies)) {
                    movies.forEach(movie => {
                        const row = $('<tr>');
                        row.append($('<td>').text(movie.id));
                        row.append($('<td>').text(movie.name));
                        row.append($('<td>').text(movie.rating));
                        $('.gridtable').append(row);
                    });
                } else {
                    console.error('返回的数据不是数组格式');
                }
            } catch (error) {
                console.error('解析JSON数据时出错:', error);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            console.error('请求失败:', textStatus, errorThrown);
            $('.gridtable').append(
                $('<tr>').append(
                    $('<td colspan="3" style="color: red; text-align: center;">')
                        .text('无法获取电影数据，请确保API服务器已启动')
                )
            );
        });
    });
</script>
</html>